package fr.imag.adele.mediation.probes.impl;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;

public class Monitor implements BundleActivator, EventHandler {
	final static String[] topics = new String[] {
		"cpu1/cpu"
		};
	
	public void start(BundleContext arg0) throws Exception {
		Dictionary d = new Hashtable();
		d.put(EventConstants.EVENT_TOPIC, topics);		
		arg0.registerService(EventHandler.class.getName(), this, d);
	}

	public void stop(BundleContext arg0) throws Exception {
		
	}


	public void handleEvent(Event arg0) {
		System.out.println("[MONITOR] Receiving... (" 
				+ arg0.getProperty("cp.event.source") 
				+ "/" + arg0.getProperty("cp.event.resource")
				+ ":{" + arg0.getProperty("cp.event.timestamp")
				+ "} " + arg0.getProperty("cp.event.value")
				+ " " + arg0.getProperty("cp.event.unit")
		);		
	}

	}
